/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package persistencia.entidade;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;

/**
 *
 * @author victorino
 */
@Entity
@Table(name = "portal_cfg", catalog = "", schema = "")
public class PortalCfg implements Serializable{
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "portal_id", nullable = false)
    private Integer portalId;
    @Basic(optional = false)
    @Column(name = "nome", nullable = false, length = 45)
    private String nome;
    @Basic(optional = false)
    @Column(name = "nome_schema", nullable = false, length = 20)
    private String nomeSchema;
    @Column(name = "titulo_mob", length = 512)
    private String tituloMob;
    @Column(name = "app_nome_mob", length = 512)
    private String appNomeMob;
    @Column(name = "exe_nome_mob", length = 512)
    private String exeNomeMob;
    @Column(name = "resumo_web", length = 512)
    private String resumoWeb;
    @Column(name = "resumo_mob", length = 100)
    private String resumoMob;
    @Lob
    @Column(name = "img_logo_mob", columnDefinition="longblob")
    private byte[] imgLogoMob;
    @Lob
    @Column(name = "img_logo_web", columnDefinition="longblob")
    private byte[] imgLogoWeb;
    @Lob
    @Column(name = "icone_mob", columnDefinition="longblob")
    private byte[] iconeMob;
    @Lob
    @Column(name = "img_buscar_mob", columnDefinition="longblob")
    private byte[] imgBuscarMob;
    @Lob
    @Column(name = "img_categoria_default_mob", columnDefinition="longblob")
    private byte[] imgCategoriaDefaultMob;
    @Lob
    @Column(name = "img_categoria_default_web", columnDefinition="longblob")
    private byte[] imgCategoriaDefaultWeb;
    @Lob
    @Column(name = "img_voltar_mob", columnDefinition="longblob")
    private byte[] imgVoltarMob;
    @Lob
    @Column(name = "img_voltar_web", columnDefinition="longblob")
    private byte[] imgVoltarWeb;
    @Lob
    @Column(name = "img_registro_default_mob", columnDefinition="longblob")
    private byte[] imgRegistroDefaultMob;
    @Lob
    @Column(name = "img_registro_default_web", columnDefinition="longblob")
    private byte[] imgRegistroDefaultWeb;

    public PortalCfg() {
    }

    public PortalCfg(Integer portalId) {
        this.portalId = portalId;
    }

    public PortalCfg(Integer portalId, String nome, String nomeSchema) {
        this.portalId = portalId;
        this.nome = nome;
        this.nomeSchema = nomeSchema;
    }

    public Integer getPortalId() {
        return portalId;
    }

    public void setPortalId(Integer portalId) {
        this.portalId = portalId;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getNomeSchema() {
        return nomeSchema;
    }

    public void setNomeSchema(String nomeSchema) {
        this.nomeSchema = nomeSchema;
    }

    public String getResumoWeb() {
        return resumoWeb;
    }

    public void setResumoWeb(String resumoWeb) {
        this.resumoWeb = resumoWeb;
    }

    public String getResumoMob() {
        return resumoMob;
    }

    public void setResumoMob(String resumoMob) {
        this.resumoMob = resumoMob;
    }

    public byte[] getImgLogoMob() {
        return imgLogoMob;
    }

    public void setImgLogoMob(byte[] imgLogoMob) {
        this.imgLogoMob = imgLogoMob;
    }

    public byte[] getImgLogoWeb() {
        return imgLogoWeb;
    }

    public void setImgLogoWeb(byte[] imgLogoWeb) {
        this.imgLogoWeb = imgLogoWeb;
    }

    public byte[] getIconeMob() {
        return iconeMob;
    }

    public void setIconeMob(byte[] iconeMob) {
        this.iconeMob = iconeMob;
    }

    public byte[] getImgBuscarMob() {
        return imgBuscarMob;
    }

    public void setImgBuscarMob(byte[] imgBuscarMob) {
        this.imgBuscarMob = imgBuscarMob;
    }

    public byte[] getImgCategoriaDefaultMob() {
        return imgCategoriaDefaultMob;
    }

    public void setImgCategoriaDefaultMob(byte[] imgCategoriaDefaultMob) {
        this.imgCategoriaDefaultMob = imgCategoriaDefaultMob;
    }

    public byte[] getImgCategoriaDefaultWeb() {
        return imgCategoriaDefaultWeb;
    }

    public void setImgCategoriaDefaultWeb(byte[] imgCategoriaDefaultWeb) {
        this.imgCategoriaDefaultWeb = imgCategoriaDefaultWeb;
    }

    public byte[] getImgVoltarMob() {
        return imgVoltarMob;
    }

    public void setImgVoltarMob(byte[] imgVoltarMob) {
        this.imgVoltarMob = imgVoltarMob;
    }

    public byte[] getImgVoltarWeb() {
        return imgVoltarWeb;
    }

    public void setImgVoltarWeb(byte[] imgVoltarWeb) {
        this.imgVoltarWeb = imgVoltarWeb;
    }

    public byte[] getImgRegistroDefaultMob() {
        return imgRegistroDefaultMob;
    }

    public void setImgRegistroDefaultMob(byte[] imgRegistroDefaultMob) {
        this.imgRegistroDefaultMob = imgRegistroDefaultMob;
    }

    public byte[] getImgRegistroDefaultWeb() {
        return imgRegistroDefaultWeb;
    }

    public void setImgRegistroDefaultWeb(byte[] imgRegistroDefaultWeb) {
        this.imgRegistroDefaultWeb = imgRegistroDefaultWeb;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (portalId != null ? portalId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PortalCfg)) {
            return false;
        }
        PortalCfg other = (PortalCfg) object;
        if ((this.portalId == null && other.portalId != null) || (this.portalId != null && !this.portalId.equals(other.portalId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "persistencia.entidade.PortalCfg[portalId=" + portalId + "]";
    }

    /**
     * @return the tituloMob
     */
    public String getTituloMob() {
        return tituloMob;
    }

    /**
     * @param tituloMob the tituloMob to set
     */
    public void setTituloMob(String tituloMob) {
        this.tituloMob = tituloMob;
    }

    /**
     * @return the appNomeMob
     */
    public String getAppNomeMob() {
        return appNomeMob;
    }

    /**
     * @param appNomeMob the appNomeMob to set
     */
    public void setAppNomeMob(String appNomeMob) {
        this.appNomeMob = appNomeMob;
    }

    /**
     * @return the exeNomeMob
     */
    public String getExeNomeMob() {
        return exeNomeMob;
    }

    /**
     * @param exeNomeMob the exeNomeMob to set
     */
    public void setExeNomeMob(String exeNomeMob) {
        this.exeNomeMob = exeNomeMob;
    }

  public String getImgLogoWebTempPath(){

        if(imgLogoWeb == null) {
            return "";
        }
        FileOutputStream fos = null;
        try {
            File file = File.createTempFile("img_", ".jpg");
            if (file.exists()) {
                file.delete();
            }

            fos = new FileOutputStream(file);
            fos.write(imgLogoWeb);
            fos.flush();
            fos.close();
            return file.getAbsolutePath().replace("\\", "/");
        } catch (Exception ex) {
            Logger.getLogger(PortalCfg.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                fos.close();
            } catch (IOException ex) {
                Logger.getLogger(PortalCfg.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return "";
    }

}
